<?php
namespace Home\Controller;
use Think\Controller;
header("Content-type:text/html;charset=utf-8");
class IndexController extends Controller {
    public function index(){
		$arr = get_ma();
		$arr['ocode'] = explode(",",$arr['opencode']);
		$m = 0;
		foreach($arr['ocode'] as $kc=>$vc){
			$m+=$vc;
		}
		$arr['total'] = $m;
		if($m>=3 && $m<=10){
			$arr['size'] = '1';//小
		}if($m>=11 && $m<=18){
			$arr['size'] = '2';//大
		}
		if($m%2!=0){
			$arr['attr'] = '1';//单
		}else{
			$arr['attr'] = '2';//双
		}
		$res = cqssc();
	//	$res = M("lottery_class")->where("id = 15")->find();
		$res["ocode"]  = explode(",",$res['opencode']);
		$r5 = xuan5();
	//	$r = M("lottery_class")->where("id = 23")->find();
		$r5["ocode"]  = explode(",",$r5['opencode']);
		$hid = I("hid");
		$this->assign("hid",$hid);
		$this->assign("arr",$arr);
		$this->assign("res",$res);
		$this->assign("r5",$r5);
//昨日奖金开始 begin
		$data = M('Accountsinfo')
		->field("userid,nickname,avatar,accounts,sex,score")
        ->select();
        $tu = array();
        foreach($data as $kk=>$vv){
        	$tu[] = $vv['userid'];
        }
        $tus = implode(",",$tu);
        $start = strtotime(date("Y-m-d",strtotime("-1 day"))." 00:00:00");
        $end = strtotime(date("Y-m-d",strtotime("-1 day"))." 23:59:59");
        if($tus){
        	$where = "uid in($tus) and ctime >= $start and ctime <= $end";
	        $sum1 = M("lottery_add")->where($where)->select();
		    $sum2 = M("lottery_ssc")->where($where)->select();
		    $sum3 = M("lottery_pk10")->where($where)->select();
		    $sum4 = M("lottery_kl8")->where($where)->select();
		    $sum5 = M("lottery_11x5")->where($where)->select();
		    $sum6 = M("lottery_fc3d")->where($where)->select();
		    $sum7 = M("zhui_kl8")->where($where)->select();
		    $sum8 = M("zhui_pk10")->where($where)->select();
		    $sum9 = M("zhui_ssc")->where($where)->select();
		    $sum10 = M("zhui_x5")->where($where)->select();
		    $where1 = "uid in($tus)";
	        $sum11 = M("lottery_add")->where($where1)->select();
		    $sum21 = M("lottery_ssc")->where($where1)->select();
		    $sum31 = M("lottery_pk10")->where($where1)->select();
		    $sum41 = M("lottery_kl8")->where($where1)->select();
		    $sum51 = M("lottery_11x5")->where($where1)->select();
		    $sum61 = M("lottery_fc3d")->where($where1)->select();
		    $sum71 = M("zhui_kl8")->where($where1)->select();
		    $sum81 = M("zhui_pk10")->where($where1)->select();
		    $sum91 = M("zhui_ssc")->where($where1)->select();
		    $sum101 = M("zhui_x5")->where($where1)->select();
        }
        foreach($data as $ka=>$va){
        	$total = 0;//总
        	$zuo = 0;//昨日
        	foreach ($sum1 as $key => $value) {
        		if($va['userid']==$value['uid']){
        			$zuo+=$value['zong_money'];
        		}
        	}
        	foreach ($sum2 as $key2 => $value2) {
        		if($va['userid']==$value2['uid']){
        			$zuo+=$value2['zong_money'];
        		}
        	}
        	foreach ($sum3 as $key3 => $value3) {
        		if($va['userid']==$value3['uid']){
        			$zuo+=$value3['zong_money'];
        		}
        	}
        	foreach ($sum4 as $key4 => $value4) {
        		if($va['userid']==$value4['uid']){
        			$zuo+=$value4['zong_money'];
        		}
        	}
        	foreach ($sum5 as $key5 => $value5) {
        		if($va['userid']==$value5['uid']){
        			$zuo+=$value5['zong_money'];
        		}
        	}
        	foreach ($sum6 as $key6 => $value6) {
        		if($va['userid']==$value6['uid']){
        			$zuo+=$value6['zong_money'];
        		}
        	}
        	foreach ($sum7 as $key7 => $value7) {
        		if($va['userid']==$value7['uid']){
        			$zuo+=$value7['zo_money'];
        		}
        	}
        	foreach ($sum8 as $key8 => $value8) {
        		if($va['userid']==$value8['uid']){
        			$zuo+=$value8['zo_money'];
        		}
        	}
        	foreach ($sum9 as $key9 => $value9) {
        		if($va['userid']==$value9['uid']){
        			$zuo+=$value9['zo_money'];
        		}
        	}
        	foreach ($sum10 as $key10 => $value10) {
        		if($va['userid']==$value10['uid']){
        			$zuo+=$value10['zong_money'];
        		}
        	}
        	foreach ($sum11 as $key1 => $value1) {
        		if($va['userid']==$value1['uid']){
        			$total+=$value1['zong_money'];
        		}
        	}
        	foreach ($sum21 as $key21 => $value21) {
        		if($va['userid']==$value21['uid']){
        			$total+=$value21['zong_money'];
        		}
        	}
        	foreach ($sum31 as $key31 => $value31) {
        		if($va['userid']==$value31['uid']){
        			$total+=$value31['zong_money'];
        		}
        	}
        	foreach ($sum41 as $key41 => $value41) {
        		if($va['userid']==$value41['uid']){
        			$total+=$value41['zong_money'];
        		}
        	}
        	foreach ($sum51 as $key51 => $value51) {
        		if($va['userid']==$value51['uid']){
        			$total+=$value51['zong_money'];
        		}
        	}
        	foreach ($sum61 as $key61 => $value61) {
        		if($va['userid']==$value61['uid']){
        			$total+=$value61['zong_money'];
        		}
        	}
        	foreach ($sum71 as $key71 => $value71) {
        		if($va['userid']==$value71['uid']){
        			$total+=$value71['zo_money'];
        		}
        	}
        	foreach ($sum81 as $key81 => $value81) {
        		if($va['userid']==$value81['uid']){
        			$total+=$value81['zo_money'];
        		}
        	}
        	foreach ($sum91 as $key91 => $value91) {
        		if($va['userid']==$value91['uid']){
        			$total+=$value91['zo_money'];
        		}
        	}
        	foreach ($sum101 as $key101 => $value101) {
        		if($va['userid']==$value101['uid']){
        			$total+=$value101['zong_money'];
        		}
        	}
        	$data[$ka]['zuo_money'] = $zuo;
        	$data[$ka]['total'] = $total;
        	if($va['score'] < '10'){
        		$touxie = 'VIP1';
        		$zhiw = "农民";
        	}elseif('10' <= $va['score'] && $va['score'] < '200'){
        		$touxie = 'VIP2';
        		$zhiw = "地主";
        	}elseif('200' <= $va['score'] && $va['score'] < '1000'){
        		$touxie = 'VIP3';
        		$zhiw = "知县";
        	}elseif('1000' <= $va['score'] && $va['score'] < '10000'){
        		$touxie = 'VIP4';
        		$zhiw = "通判";
        	}elseif('10000' <= $va['score'] && $va['score'] < '50000'){
        		$touxie = 'VIP5';
        		$zhiw = "知府";
        	}elseif('50000' <= $va['score'] && $va['score'] < '250000'){
        		$touxie = 'VIP6';
        		$zhiw = "总督";
        	}elseif('250000' <= $va['score'] && $va['score'] < '1000000'){
        		$touxie = 'VIP7';
        		$zhiw = "巡抚";
        	}elseif('1000000' <= $va['score'] && $va['score'] < '5000000'){
        		$touxie = 'VIP8';
        		$zhiw = "丞相";
        	}elseif('5000000' <= $va['score']){
        		$touxie = 'VIP9';
        		$zhiw = "帝王";
        	}
        	$data[$ka]['touxie'] = $touxie;
        	$data[$ka]['zhiw'] = $zhiw;
        	if($va['sex']=='1'){
        		$sex = "男";
        	}if($va['sex']=='2'){
        		$sex = "女";
        	}if($va['sex']=='3'){
        		$sex = "保密";
        	}
        	$data[$ka]['sex'] = $sex;
        }
        $ages = array();
		foreach ($data as $user) {
		  $ages[] = $user['zuo_money'];
		}
		array_multisort($ages, SORT_DESC, $data);
		$da = array_slice($data,0,3);
		$this->assign("da",$da);
//昨日奖金开始 end

		$r1 = M("lottery_add la")
            ->join(" join ".C("DB_PREFIX")."accountsinfo a on la.uid=a.userid")
            ->join(" join ".C("DB_PREFIX")."lottery_class c on la.lotteryclass=c.id")
            ->where("la.zong_money>0")
            ->field("la.uid,la.lotteryclass,la.zong_money,a.sex,a.accounts,a.score,a.avatar,a.nickname,la.ctime,c.name")
            ->select();
        $r2 = M("lottery_ssc ls")
            ->join(" join ".C("DB_PREFIX")."accountsinfo a on ls.uid=a.userid")
            ->join(" join ".C("DB_PREFIX")."lottery_class c on ls.lotteryclass=c.id")
            ->where("ls.zong_money>0")
            ->field("ls.uid,ls.lotteryclass,ls.zong_money,a.sex,a.accounts,a.score,a.avatar,a.nickname,ls.ctime,c.name")
            ->select();
        $r3 = M("lottery_pk10 lp")
            ->join(" join ".C("DB_PREFIX")."accountsinfo a on lp.uid=a.userid")
            ->join(" join ".C("DB_PREFIX")."lottery_class c on lp.lotteryclass=c.id")
            ->where("lp.zong_money>0")
            ->field("lp.uid,lp.lotteryclass,lp.zong_money,a.sex,a.accounts,a.score,a.avatar,a.nickname,lp.ctime,c.name")
            ->select();
        $r4 = M("lottery_kl8 lk")
            ->join(" join ".C("DB_PREFIX")."accountsinfo a on lk.uid=a.userid")
            ->join(" join ".C("DB_PREFIX")."lottery_class c on lk.lotteryclass=c.id")
            ->where("lk.zong_money>0")
            ->field("lk.uid,lk.lotteryclass,lk.zong_money,a.sex,a.accounts,a.score,a.avatar,a.nickname,lk.ctime,c.name")
            ->select();
        $r5 = M("lottery_11x5 l1")
            ->join(" join ".C("DB_PREFIX")."accountsinfo a on l1.uid=a.userid")
            ->join(" join ".C("DB_PREFIX")."lottery_class c on l1.lotteryclass=c.id")
            ->where("l1.zong_money>0")
            ->field("l1.uid,l1.lotteryclass,l1.zong_money,a.sex,a.accounts,a.score,a.avatar,a.nickname,l1.ctime,c.name")
            ->select();
        $r6 = M("lottery_fc3d lf")
            ->join(" join ".C("DB_PREFIX")."accountsinfo a on lf.uid=a.userid")
            ->join(" join ".C("DB_PREFIX")."lottery_class c on lf.lotteryclass=c.id")
            ->where("lf.zong_money>0")
            ->field("lf.uid,lf.lotteryclass,lf.zong_money,a.sex,a.accounts,a.score,a.avatar,a.nickname,lf.ctime,c.name")
            ->select();
        $r7 = M("zhui_kl8 zk")
            ->join(" join ".C("DB_PREFIX")."accountsinfo a on zk.uid=a.userid")
            ->join(" join ".C("DB_PREFIX")."lottery_class c on zk.lotteryclass=c.id")
            ->where("zk.zo_money>0")
            ->field("zk.uid,zk.lotteryclass,zk.zo_money as zong_money,a.sex,a.accounts,a.score,a.avatar,a.nickname,zk.ctime,c.name")
            ->select();
        $r8 = M("zhui_pk10 zp")
            ->join(" join ".C("DB_PREFIX")."accountsinfo a on zp.uid=a.userid")
            ->join(" join ".C("DB_PREFIX")."lottery_class c on zp.lotteryclass=c.id")
            ->where("zp.zo_money>0")
            ->field("zp.uid,zp.lotteryclass,zp.zo_money as zong_money,a.sex,a.accounts,a.score,a.avatar,a.nickname,zp.ctime,c.name")
            ->select();
        $r9 = M("zhui_ssc zs")
            ->join(" join ".C("DB_PREFIX")."accountsinfo a on zs.uid=a.userid")
            ->join(" join ".C("DB_PREFIX")."lottery_class c on zs.lotteryclass=c.id")
            ->where("zs.zo_money>0")
            ->field("zs.uid,zs.lotteryclass,zs.zo_money as zong_money,a.sex,a.accounts,a.score,a.avatar,a.nickname,zs.ctime,c.name")
            ->select();
        $r10 = M("zhui_x5 zx")
            ->join(" join ".C("DB_PREFIX")."accountsinfo a on zx.uid=a.userid")
            ->join(" join ".C("DB_PREFIX")."lottery_class c on zx.lotteryclass=c.id")
            ->where("zx.zo_money>0")
            ->field("zx.uid,zx.lotteryclass,zx.zo_money as zong_money,a.sex,a.accounts,a.score,a.avatar,a.nickname,zx.ctime,c.name")
            ->select();
        $r = array_merge($r1,$r2,$r3,$r4,$r5,$r6,$r7,$r8,$r9,$r10);
        $tu1 = array();
        foreach($r as $kp=>$vp){
        	$tu1[] = $vp['uid'];
        }
        $tuss = implode(",",$tu1);
        if($tuss){
		    $where1 = "uid in($tuss)";
	        $sum11 = M("lottery_add")->where($where1)->select();
		    $sum21 = M("lottery_ssc")->where($where1)->select();
		    $sum31 = M("lottery_pk10")->where($where1)->select();
		    $sum41 = M("lottery_kl8")->where($where1)->select();
		    $sum51 = M("lottery_11x5")->where($where1)->select();
		    $sum61 = M("lottery_fc3d")->where($where1)->select();
		    $sum71 = M("zhui_kl8")->where($where1)->select();
		    $sum81 = M("zhui_pk10")->where($where1)->select();
		    $sum91 = M("zhui_ssc")->where($where1)->select();
		    $sum101 = M("zhui_x5")->where($where1)->select();
        }
        foreach($r as $ka1=>$va){
        	$total = 0;//总
        	foreach ($sum11 as $key1 => $value1) {
        		if($va['uid']==$value1['uid']){
        			$total+=$value1['zong_money'];
        		}
        	}
        	foreach ($sum21 as $key21 => $value21) {
        		if($va['uid']==$value21['uid']){
        			$total+=$value21['zong_money'];
        		}
        	}
        	foreach ($sum31 as $key31 => $value31) {
        		if($va['uid']==$value31['uid']){
        			$total+=$value31['zong_money'];
        		}
        	}
        	foreach ($sum41 as $key41 => $value41) {
        		if($va['uid']==$value41['uid']){
        			$total+=$value41['zong_money'];
        		}
        	}
        	foreach ($sum51 as $key51 => $value51) {
        		if($va['uid']==$value51['uid']){
        			$total+=$value51['zong_money'];
        		}
        	}
        	foreach ($sum61 as $key61 => $value61) {
        		if($va['uid']==$value61['uid']){
        			$total+=$value61['zong_money'];
        		}
        	}
        	foreach ($sum71 as $key71 => $value71) {
        		if($va['uid']==$value71['uid']){
        			$total+=$value71['zo_money'];
        		}
        	}
        	foreach ($sum81 as $key81 => $value81) {
        		if($va['uid']==$value81['uid']){
        			$total+=$value81['zo_money'];
        		}
        	}
        	foreach ($sum91 as $key91 => $value91) {
        		if($va['uid']==$value91['uid']){
        			$total+=$value91['zo_money'];
        		}
        	}
        	foreach ($sum101 as $key101 => $value101) {
        		if($va['uid']==$value101['uid']){
        			$total+=$value101['zo_money'];
        		}
        	}
        	$r[$ka1]['total'] = $total;
        	if($va['score'] < '10'){
        		$touxie = 'VIP1';
        		$zhiw = "农民";
        	}elseif('10' <= $va['score'] && $va['score'] < '200'){
        		$touxie = 'VIP2';
        		$zhiw = "地主";
        	}elseif('200' <= $va['score'] && $va['score'] < '1000'){
        		$touxie = 'VIP3';
        		$zhiw = "知县";
        	}elseif('1000' <= $va['score'] && $va['score'] < '10000'){
        		$touxie = 'VIP4';
        		$zhiw = "通判";
        	}elseif('10000' <= $va['score'] && $va['score'] < '50000'){
        		$touxie = 'VIP5';
        		$zhiw = "知府";
        	}elseif('50000' <= $va['score'] && $va['score'] < '250000'){
        		$touxie = 'VIP6';
        		$zhiw = "总督";
        	}elseif('250000' <= $va['score'] && $va['score'] < '1000000'){
        		$touxie = 'VIP7';
        		$zhiw = "巡抚";
        	}elseif('1000000' <= $va['score'] && $va['score'] < '5000000'){
        		$touxie = 'VIP8';
        		$zhiw = "丞相";
        	}elseif('5000000' <= $va['score']){
        		$touxie = 'VIP9';
        		$zhiw = "帝王";
        	}
        	$r[$ka1]['touxie'] = $touxie;
        	$r[$ka1]['zhiw'] = $zhiw;
        	if($va['sex']=='1'){
        		$sex = "男";
        	}if($va['sex']=='2'){
        		$sex = "女";
        	}if($va['sex']=='3'){
        		$sex = "保密";
        	}
        	$r[$ka1]['sex'] = $sex;
        }
        $age = array();
		foreach ($r as $users) {
		  $age[] = $users['ctime'];
		}
		array_multisort($age, SORT_DESC, $r);


		$data1 = M("notice")->select();


		$this->assign("data1",$data1);
		$this->assign("r",$r);
        $this->display();
    }
	public function lotteryHall(){
		$hid = I("hid");
		$this->assign("hid",$hid);
        $r1 = M("lottery_add la")
            ->join(" join ".C("DB_PREFIX")."accountsinfo a on la.uid=a.userid")
            ->join(" join ".C("DB_PREFIX")."lottery_class c on la.lotteryclass=c.id")
            ->where("la.zong_money>0")
            ->field("la.uid,la.lotteryclass,la.zong_money,a.sex,a.accounts,a.score,a.avatar,a.nickname,la.ctime,c.name")
            ->select();
        $r2 = M("lottery_ssc ls")
            ->join(" join ".C("DB_PREFIX")."accountsinfo a on ls.uid=a.userid")
            ->join(" join ".C("DB_PREFIX")."lottery_class c on ls.lotteryclass=c.id")
            ->where("ls.zong_money>0")
            ->field("ls.uid,ls.lotteryclass,ls.zong_money,a.sex,a.accounts,a.score,a.avatar,a.nickname,ls.ctime,c.name")
            ->select();
        $r3 = M("lottery_pk10 lp")
            ->join(" join ".C("DB_PREFIX")."accountsinfo a on lp.uid=a.userid")
            ->join(" join ".C("DB_PREFIX")."lottery_class c on lp.lotteryclass=c.id")
            ->where("lp.zong_money>0")
            ->field("lp.uid,lp.lotteryclass,lp.zong_money,a.sex,a.accounts,a.score,a.avatar,a.nickname,lp.ctime,c.name")
            ->select();
        $r4 = M("lottery_kl8 lk")
            ->join(" join ".C("DB_PREFIX")."accountsinfo a on lk.uid=a.userid")
            ->join(" join ".C("DB_PREFIX")."lottery_class c on lk.lotteryclass=c.id")
            ->where("lk.zong_money>0")
            ->field("lk.uid,lk.lotteryclass,lk.zong_money,a.sex,a.accounts,a.score,a.avatar,a.nickname,lk.ctime,c.name")
            ->select();
        $r5 = M("lottery_11x5 l1")
            ->join(" join ".C("DB_PREFIX")."accountsinfo a on l1.uid=a.userid")
            ->join(" join ".C("DB_PREFIX")."lottery_class c on l1.lotteryclass=c.id")
            ->where("l1.zong_money>0")
            ->field("l1.uid,l1.lotteryclass,l1.zong_money,a.sex,a.accounts,a.score,a.avatar,a.nickname,l1.ctime,c.name")
            ->select();
        $r6 = M("lottery_fc3d lf")
            ->join(" join ".C("DB_PREFIX")."accountsinfo a on lf.uid=a.userid")
            ->join(" join ".C("DB_PREFIX")."lottery_class c on lf.lotteryclass=c.id")
            ->where("lf.zong_money>0")
            ->field("lf.uid,lf.lotteryclass,lf.zong_money,a.sex,a.accounts,a.score,a.avatar,a.nickname,lf.ctime,c.name")
            ->select();
        $r7 = M("zhui_kl8 zk")
            ->join(" join ".C("DB_PREFIX")."accountsinfo a on zk.uid=a.userid")
            ->join(" join ".C("DB_PREFIX")."lottery_class c on zk.lotteryclass=c.id")
            ->where("zk.zo_money>0")
            ->field("zk.uid,zk.lotteryclass,zk.zo_money as zong_money,a.sex,a.accounts,a.score,a.avatar,a.nickname,zk.ctime,c.name")
            ->select();
        $r8 = M("zhui_pk10 zp")
            ->join(" join ".C("DB_PREFIX")."accountsinfo a on zp.uid=a.userid")
            ->join(" join ".C("DB_PREFIX")."lottery_class c on zp.lotteryclass=c.id")
            ->where("zp.zo_money>0")
            ->field("zp.uid,zp.lotteryclass,zp.zo_money as zong_money,a.sex,a.accounts,a.score,a.avatar,a.nickname,zp.ctime,c.name")
            ->select();
        $r9 = M("zhui_ssc zs")
            ->join(" join ".C("DB_PREFIX")."accountsinfo a on zs.uid=a.userid")
            ->join(" join ".C("DB_PREFIX")."lottery_class c on zs.lotteryclass=c.id")
            ->where("zs.zo_money>0")
            ->field("zs.uid,zs.lotteryclass,zs.zo_money as zong_money,a.sex,a.accounts,a.score,a.avatar,a.nickname,zs.ctime,c.name")
            ->select();
        $r10 = M("zhui_x5 zx")
            ->join(" join ".C("DB_PREFIX")."accountsinfo a on zx.uid=a.userid")
            ->join(" join ".C("DB_PREFIX")."lottery_class c on zx.lotteryclass=c.id")
            ->where("zx.zo_money>0")
            ->field("zx.uid,zx.lotteryclass,zx.zo_money as zong_money,a.sex,a.accounts,a.score,a.avatar,a.nickname,zx.ctime,c.name")
            ->select();
        $r = array_merge($r1,$r2,$r3,$r4,$r5,$r6,$r7,$r8,$r9,$r10);
        $tu1 = array();
        foreach($r as $kp=>$vp){
            $tu1[] = $vp['uid'];
        }
        $tuss = implode(",",$tu1);
        if($tuss){
            $where1 = "uid in($tuss)";
            $sum11 = M("lottery_add")->where($where1)->select();
            $sum21 = M("lottery_ssc")->where($where1)->select();
            $sum31 = M("lottery_pk10")->where($where1)->select();
            $sum41 = M("lottery_kl8")->where($where1)->select();
            $sum51 = M("lottery_11x5")->where($where1)->select();
            $sum61 = M("lottery_fc3d")->where($where1)->select();
            $sum71 = M("zhui_kl8")->where($where1)->select();
            $sum81 = M("zhui_pk10")->where($where1)->select();
            $sum91 = M("zhui_ssc")->where($where1)->select();
            $sum101 = M("zhui_x5")->where($where1)->select();
        }
        foreach($r as $ka1=>$va){
            $total = 0;//总
            foreach ($sum11 as $key1 => $value1) {
                if($va['uid']==$value1['uid']){
                    $total+=$value1['zong_money'];
                }
            }
            foreach ($sum21 as $key21 => $value21) {
                if($va['uid']==$value21['uid']){
                    $total+=$value21['zong_money'];
                }
            }
            foreach ($sum31 as $key31 => $value31) {
                if($va['uid']==$value31['uid']){
                    $total+=$value31['zong_money'];
                }
            }
            foreach ($sum41 as $key41 => $value41) {
                if($va['uid']==$value41['uid']){
                    $total+=$value41['zong_money'];
                }
            }
            foreach ($sum51 as $key51 => $value51) {
                if($va['uid']==$value51['uid']){
                    $total+=$value51['zong_money'];
                }
            }
            foreach ($sum61 as $key61 => $value61) {
                if($va['uid']==$value61['uid']){
                    $total+=$value61['zong_money'];
                }
            }
            foreach ($sum71 as $key71 => $value71) {
                if($va['uid']==$value71['uid']){
                    $total+=$value71['zo_money'];
                }
            }
            foreach ($sum81 as $key81 => $value81) {
                if($va['uid']==$value81['uid']){
                    $total+=$value81['zo_money'];
                }
            }
            foreach ($sum91 as $key91 => $value91) {
                if($va['uid']==$value91['uid']){
                    $total+=$value91['zo_money'];
                }
            }
            foreach ($sum101 as $key101 => $value101) {
                if($va['uid']==$value101['uid']){
                    $total+=$value101['zo_money'];
                }
            }
            $r[$ka1]['total'] = $total;
            if($va['score'] < '10'){
                $touxie = 'VIP1';
                $zhiw = "农民";
            }elseif('10' <= $va['score'] && $va['score'] < '200'){
                $touxie = 'VIP2';
                $zhiw = "地主";
            }elseif('200' <= $va['score'] && $va['score'] < '1000'){
                $touxie = 'VIP3';
                $zhiw = "知县";
            }elseif('1000' <= $va['score'] && $va['score'] < '10000'){
                $touxie = 'VIP4';
                $zhiw = "通判";
            }elseif('10000' <= $va['score'] && $va['score'] < '50000'){
                $touxie = 'VIP5';
                $zhiw = "知府";
            }elseif('50000' <= $va['score'] && $va['score'] < '250000'){
                $touxie = 'VIP6';
                $zhiw = "总督";
            }elseif('250000' <= $va['score'] && $va['score'] < '1000000'){
                $touxie = 'VIP7';
                $zhiw = "巡抚";
            }elseif('1000000' <= $va['score'] && $va['score'] < '5000000'){
                $touxie = 'VIP8';
                $zhiw = "丞相";
            }elseif('5000000' <= $va['score']){
                $touxie = 'VIP9';
                $zhiw = "帝王";
            }
            $r[$ka1]['touxie'] = $touxie;
            $r[$ka1]['zhiw'] = $zhiw;
            if($va['sex']=='1'){
                $sex = "男";
            }if($va['sex']=='2'){
                $sex = "女";
            }if($va['sex']=='3'){
                $sex = "保密";
            }
            $r[$ka1]['sex'] = $sex;
        }
        $age = array();
        foreach ($r as $users) {
          $age[] = $users['ctime'];
        }
        array_multisort($age, SORT_DESC, $r);
        $this->assign("r",$r);
        $this->display();
    }
	public function activity(){
		if($_POST){
			$id = $_SESSION['user_id'];
			if($id){
				$Accountsinfo = M('Accountsinfo')->where("userid = {$id}")->field("money")->find();
			}

			$type = I("type");
			if($type == '1'){
				$up = M('up_level')->where("uid = {$id} and type={$type}")->field("is_lingqu")->find();
				if($up['is_lingqu'] == 1){
					echo 2;die;
				}

				//晋级奖励
				$jiangjin = I("jiangjin");
				$dat0['kl_money'] = $jiangjin;
				$dat0['is_lingqu'] = 1;
				$dat0['lq_time'] = time();
				M("up_level")->where("uid={$id} and type={$type}")->save($dat0);
                $money = $jiangjin;
				//晋级奖励改变money
				$up_level = M('up_level')->where("uid = {$id} and type={$type}")->find();
				$dat1['money'] = $Accountsinfo['money'] + $up_level['kl_money'];

				M('Accountsinfo')->where("userid = {$id}")->save($dat1);
				$date11 = M('Accountsinfo')->where("userid = {$id}")->find();

				$cp['number'] = date("Ymd").rand(100000,999999);
				$cp['type'] = '7';
				$cp['shou_money'] = $jiangjin;
				$cp['zhi_money'] = 0;
				$cp['ky_money'] = $date11['money'];
				$cp['ctime'] = time();
				$cp['uid'] = $id;
				$cp['remark'] = '活动礼金';
				M("jiaoyi")->add($cp);
				echo 1,$money;
			}elseif($type == '3'){
				$up = M('up_level')->where("uid = {$id} and type={$type}")->field("is_lingqu")->find();
				if($up['is_lingqu'] == 1){
					echo 2;die;
				}

				//每天欢乐颂奖励
				$jiangjin123 = I("jiangjin123");
				$dat2['kl_money'] = $jiangjin123;
				$dat2['is_lingqu'] = 1;
				$dat2['lq_time'] = time();
				M("up_level")->where("uid={$id} and type={$type}")->save($dat2);
				//每天欢乐颂改变money
				$up_level1 = M('up_level')->where("uid = {$id} and type={$type}")->find();
				$dat3['money'] = $Accountsinfo['money'] + $up_level1['kl_money'];
				M('Accountsinfo')->where("userid = {$id}")->save($dat3);
				$date11 = M('Accountsinfo')->where("userid = {$id}")->find();
				$cp['number'] = date("Ymd").rand(100000,999999);
				$cp['type'] = '7';
				$cp['shou_money'] = $jiangjin123;
				$cp['zhi_money'] = 0;
				$cp['ky_money'] = $date11['money'];
				$cp['ctime'] = time();
				$cp['uid'] = $id;
				$cp['remark'] = '活动礼金';
				M("jiaoyi")->add($cp);

				$money = $jiangjin123;
				echo 1,$money;
			}elseif($type == '6'){
				$up = M('up_level')->where("uid = {$id} and type={$type}")->field("is_lingqu")->find();
				if($up['is_lingqu'] == 1){
					echo 2;die;
				}

				//生日红包奖励
				$hongbao = I("shengri");
				$dat4['kl_money'] = $hongbao;
				$dat4['is_lingqu'] = 1;
				$dat4['lq_time'] = time();
				M("up_level")->where("uid={$id} and type={$type}")->save($dat4);
				//每天欢乐颂改变money
				$up_level2 = M('up_level')->where("uid = {$id} and type={$type}")->find();
				$dat5['money'] = $Accountsinfo['money'] + $up_level2['kl_money'];
				M('Accountsinfo')->where("userid = {$id}")->save($dat5);
				$date11 = M('Accountsinfo')->where("userid = {$id}")->find();
				$cp['number'] = date("Ymd").rand(100000,999999);
				$cp['type'] = '7';
				$cp['shou_money'] = $hongbao;
				$cp['zhi_money'] = 0;
				$cp['ky_money'] = $date11['money'];
				$cp['ctime'] = time();
				$cp['uid'] = $id;
				$cp['remark'] = '活动礼金';
				M("jiaoyi")->add($cp);
				echo 1,$hongbao;
			}elseif($type == '4'){

				$up = M('up_level')->where("uid = {$id} and type={$type}")->field("is_lingqu")->find();
				if($up['is_lingqu'] == 1){
					echo 2;die;
				}

				//先到先得奖励
				$hong= rand(5,28);
				$dd['uid'] = $id;
				$dd['lq_money'] = $hong;
				$dd['lq_time'] = time();
				$dat6['kl_money'] = $hong;
				$dat6['is_lingqu'] = 1;
				$dat6['lq_time'] = time();
				M("firstcome")->add($dd);
				M("up_level")->where("uid={$id} and type={$type}")->save($dat6);

				//先到先得改变money
				$up_level3 = M('up_level')->where("uid = {$id} and type={$type}")->find();
				$dat7['money'] = $Accountsinfo['money'] + $up_level3['kl_money'];
				M('Accountsinfo')->where("userid = {$id}")->save($dat7);
				$date11 = M('Accountsinfo')->where("userid = {$id}")->find();
				$cp['number'] = date("Ymd").rand(100000,999999);
				$cp['type'] = '7';
				$cp['shou_money'] = $hong;
				$cp['zhi_money'] = 0;
				$cp['ky_money'] = $date11['money'];
				$cp['ctime'] = time();
				$cp['uid'] = $id;
				$cp['remark'] = '活动礼金';
				M("jiaoyi")->add($cp);
				echo 1,$hong;
			}elseif($type == '5'){

				$up = M('up_level')->where("uid = {$id} and type={$type}")->field("is_lingqu")->find();
				if($up['is_lingqu'] == 1){
					echo 12;die;
				}

				//充值奖励
				$huizeng = I("huizeng");
				$dat61['kl_money'] = $huizeng;
				$dat61['is_lingqu'] = 1;
				$dat61['lq_time'] = time();
				M("up_level")->where("uid={$id} and type={$type}")->save($dat61);

				//充值奖励改变money
				$up_level31 = M('up_level')->where("uid = {$id} and type={$type}")->find();
				$dat71['money'] = $Accountsinfo['money'] + $up_level31['kl_money'];
				M('Accountsinfo')->where("userid = {$id}")->save($dat71);
				$date112 = M('Accountsinfo')->where("userid = {$id}")->find();
				$cp['number'] = date("Ymd").rand(100000,999999);
				$cp['type'] = '7';
				$cp['shou_money'] = $huizeng;
				$cp['zhi_money'] = 0;
				$cp['ky_money'] = $date112['money'];
				$cp['ctime'] = time();
				$cp['uid'] = $id;
				$cp['remark'] = '活动礼金';
				M("jiaoyi")->add($cp);
				echo 1,$huizeng;
			}elseif($type == '7'){

				$up = M('up_level')->where("uid = {$id} and type={$type}")->field("is_lingqu")->find();
				if($up['is_lingqu'] == 1){
					echo 13;die;
				}

				//推广奖励
				$tuiguang = I("tuiguang");
				$dat62['kl_money'] = $tuiguang;
				$dat62['is_lingqu'] = 1;
				$dat62['lq_time'] = time();
				M("up_level")->where("uid={$id} and type={$type}")->save($dat62);

				//推广奖励改变money
				$up_level32 = M('up_level')->where("uid = {$id} and type={$type}")->find();
				$dat72['money'] = $Accountsinfo['money'] + $up_level32['kl_money'];
				M('Accountsinfo')->where("userid = {$id}")->save($dat72);
				$date113 = M('Accountsinfo')->where("userid = {$id}")->find();
				$cp['number'] = date("Ymd").rand(100000,999999);
				$cp['type'] = '7';
				$cp['shou_money'] = $tuiguang;
				$cp['zhi_money'] = 0;
				$cp['ky_money'] = $date113['money'];
				$cp['ctime'] = time();
				$cp['uid'] = $id;
				$cp['remark'] = '活动礼金';
				M("jiaoyi")->add($cp);
				echo 1,$tuiguang;
			}
		}else{
			$id = $_SESSION['user_id'];
			//晋级奖励
			if($id==""){

			}else {
				$up_level = M('up_level')->where("uid = {$id} and type='1'")->find();
			}

			//
			//每日加奖
			if($id==""){

			}else {
				$up_leves = M('up_level')->where("uid = {$id} and type='2'")->find();
			}
			//条件
			$where = array();
			$where['uid'] = $id;
			$stime = date('Y-m-d',strtotime('-1 day'))." 00:00:00";//昨天开始时间
			$etime = date('Y-m-d',strtotime('-1 day'))." 23:59:59";//昨天结束时间
			$stimes = strtotime($stime);
			$etimes = strtotime($etime);
			$where['ctime'] = array(array('egt',$stimes),array('elt',$etimes));
			//查表
			$data1 = M('lottery_add')->where($where) ->select();
			$data2 = M('lottery_11x5')->where($where)->select();
			$data3 = M('lottery_fc3d')->where($where)->select();
			$data4 = M('lottery_kl8')->where($where) ->select();
			$data5 = M('lottery_pk10')->where($where)->select();
			$data6 = M('lottery_ssc')->where($where)->select();
			$data = array_merge($data1,$data2,$data3,$data4,$data5,$data6);
			$touzhus = 0;   //投注钱数
			foreach($data as $v){
				$touzhus += $v["money"];
			}
			$touzhu = sprintf("%.2f", $touzhus);

			//加奖比例
			$bili = 0;
			if($up_leves['level']=='3' && '100'<=$touzhu){
				$bili = 0.6;
			}elseif($up_leves['level']=='4' && '100'<=$touzhu){
				$bili = 0.7;
			}elseif($up_leves['level']=='5' && '100'<=$touzhu){
				$bili = 0.8;
			}elseif($up_leves['level']=='6' && '100'<=$touzhu){
				$bili = 0.9;
			}elseif($up_leves['level']=='7' && '100'<=$touzhu){
				$bili = 0.10;
			}elseif($up_leves['level']=='8' && '100'<=$touzhu){
				$bili = 1.1;
			}elseif($up_leves['level']=='9' && '100'<=$touzhu){
				$bili = 1.2;
			}

			//可得嘉奖
			$jiajiang = 0;
			if($up_leves['level']=='3' && '100'<=$touzhu){
				$jiajiang1 = $touzhu * 0.006;
				$jiajiang  = sprintf("%.2f", $jiajiang1);
			}elseif($up_leves['level']=='4' && '100'<=$touzhu){
				$jiajiang2 = $touzhu * 0.007;
				$jiajiang  = sprintf("%.2f", $jiajiang2);
			}elseif($up_leves['level']=='5' && '100'<=$touzhu){
				$jiajiang3 = $touzhu * 0.008;
				$jiajiang  = sprintf("%.2f", $jiajiang3);
			}elseif($up_leves['level']=='6' && '100'<=$touzhu){
				$jiajiang4 = $touzhu * 0.009;
				$jiajiang  = sprintf("%.2f", $jiajiang4);
			}elseif($up_leves['level']=='7' && '100'<=$touzhu){
				$jiajiang5 = $touzhu * 0.010;
				$jiajiang  = sprintf("%.2f", $jiajiang5);
			}elseif($up_leves['level']=='8' && '100'<=$touzhu){
				$jiajiang6 = $touzhu * 0.011;
				$jiajiang  = sprintf("%.2f", $jiajiang6);
			}elseif($up_leves['level']=='9' && '100'<=$touzhu){
				$jiajiang7 = $touzhu * 0.012;
				$jiajiang  = sprintf("%.2f", $jiajiang7);
			}


			//每天欢乐颂
			if($id==""){

			}else {
				$up_level1 = M('up_level')->where("uid = {$id} and type='3'")->find();
			}
			if($id){
				$Accountsinfo = M('Accountsinfo')->where("userid = {$id}")->field("money,birth")->find();
			}

//         var_dump($up_level1);die;
			//今日投注
			//条件
			$where1 = array();
			$where1['uid'] = $id;
			$stime1 = date('Y-m-d',time())." 09:30:00";//当天开始时间
			$etime1 = date('Y-m-d',time())." 23:50:00";//当天结束时间
			$stimes1 = strtotime($stime1);
			$etimes1 = strtotime($etime1);
			$where1['ctime'] = array(array('egt',$stimes1),array('elt',$etimes1));
			//查表
			$data11 = M('lottery_add')->where($where1) ->select();
			$data21 = M('lottery_11x5')->where($where1)->select();
			$data31 = M('lottery_fc3d')->where($where1)->select();
			$data41 = M('lottery_kl8')->where($where1) ->select();
			$data51 = M('lottery_pk10')->where($where1)->select();
			$data61 = M('lottery_ssc')->where($where1)->select();
			$data1 = array_merge($data11,$data21,$data31,$data41,$data51,$data61);
			$touzhus1 = 0;   //投注钱数
			foreach($data1 as $v){
				$touzhus1 += $v["money"];
			}
			$touzhu1 = sprintf("%.2f", $touzhus1);

			//可得奖金 begion
			if( '888'<= $touzhu1 &&  $touzhu1< '8888' && $Accountsinfo['money'] > '88'){
				$jiang_jin = 8.00;
			}elseif( '8888'<= $touzhu1 && $touzhu1< '88888'  && $Accountsinfo['money'] > '888'){
				$jiang_jin = 58.00;
			}elseif($touzhu1 >= '88888' && $Accountsinfo['money'] > '8888'){
				$jiang_jin = 388.00;
			};
			$jiang_jins= sprintf("%.2f", $jiang_jin);

			//end

			//充值回赠 begion
			if($id==""){}else {
				$chongzhi = M('up_level')->where("uid = {$id} and type='5'")->find();
				$jiaoyi = M("jiaoyi")->where("uid={$id} and type=1")->select();
			}

			$jiaoyi1 = array_slice($jiaoyi,-1,1);
            foreach($jiaoyi1 as $v){
				$shou_money = $v['shou_money'];
			}
			$shou_money  = sprintf("%.2f", $shou_money);
			//可得嘉奖
			$huizeng = 0;
			if($chongzhi['level']==3 && 100<= $shou_money){
				$chongzhi1 = $shou_money * 0.006;
				$huizeng  = sprintf("%.2f", $chongzhi1);
			}elseif($chongzhi['level']==4 && 100<= $shou_money){
				$chongzhi2 = $shou_money * 0.007;
				$huizeng  = sprintf("%.2f", $chongzhi2);
			}elseif($chongzhi['level']==5 && 100<= $shou_money){
				$chongzhi3 = $shou_money * 0.008;
				$huizeng  = sprintf("%.2f", $chongzhi3);
			}elseif($chongzhi['level']==6 && 100<= $shou_money){
				$chongzhi4 = $shou_money * 0.009;
				$huizeng  = sprintf("%.2f", $chongzhi4);
			}elseif($chongzhi['level']==7 && 100<= $shou_money){
				$chongzhi5 = $shou_money * 0.010;
				$huizeng  = sprintf("%.2f", $chongzhi5);
			}elseif($chongzhi['level']==8 && 100<= $shou_money){
				$chongzhi6 = $shou_money * 0.011;
				$huizeng  = sprintf("%.2f", $chongzhi6);
			}elseif($chongzhi['level']==9 && '100'<= $shou_money){
				$chongzhi7 = $shou_money * 0.012;
				$huizeng  = sprintf("%.2f", $chongzhi7);
			}
           //充值回赠 end


			//生日日期 begion
			$birth = trim($Accountsinfo['birth']);

           if($birth){
			   $births = strtotime($birth);
			   $birth1 = date("m-d",$births);
		   }
			$time = date('m-d',time());

			if($birth1==$time){
				if($id){
					$up_level2 = M('up_level')->where("uid = {$id} and type='6'")->find();
				}
			}else{
				$up_level2 = NULL;
			}
			$stime111 = date('Y-m-d',time())." 00:00:00";
			$etime111 = date('Y-m-d',time())." 23:59:59";
			$stimes111 = strtotime($stime111);
			$etimes111 = strtotime($etime111);


			//生日红包
			$hongbao = 0;
			if($up_level['level']=='5'){
				$hongbao1 = '38';
				$hongbao  = sprintf("%.2f", $hongbao1);
			}elseif($up_level['level']=='6'){
				$hongbao2 = '58';
				$hongbao  = sprintf("%.2f", $hongbao2);
			}elseif($up_level['level']=='7'){
				$hongbao3 = '88';
				$hongbao  = sprintf("%.2f", $hongbao3);
			}elseif($up_level['level']=='8'){
				$hongbao4 = '188';
				$hongbao  = sprintf("%.2f", $hongbao4);
			}elseif($up_level['level']=='9'){
				$hongbao5 = '888';
				$hongbao  = sprintf("%.2f", $hongbao5);
			}
			//end

			//先到先得 begion
			if($id==""){

			}else {
				$up_level4 = M('up_level')->where("uid = {$id} and type='4'")->find();
			}


			//条件1  上半场
			$stime12 = date('Y-m-d',time())."  08:30:00";
			$etime12 = date('Y-m-d',time())."  12:30:00";
			$stimes12 = strtotime($stime12);
			$etimes12 = strtotime($etime12);
			$first1 = M("firstcome")->where("{$stimes12} <= lq_time and lq_time <= {$etimes12}")->select();
			$count = count($first1);


			//条件1  下半场
			$stime13 = date('Y-m-d',time())."  18:30:00";
			$etime13 = date('Y-m-d',time())."  22:30:00";
			$stimes13 = strtotime($stime13);
			$etimes13 = strtotime($etime13);
			$first2 = M("firstcome")->where("{$stimes13} <= lq_time and lq_time <= {$etimes13}")->select();
			$count2 = count($first2);
			$timess = time();
			//end


	//推广好礼 begion
			if($id==""){

			}else {
				$tuiguang = M('up_level')->where("uid = {$id} and type='7'")->find();
				$agent = M("agent")->where("uid={$id}")->field("code")->select();//查邀请码
			}


			foreach($agent as $v){
				$code[] = $v["code"];
			}
			$codes = implode(",",$code);
			//查找所有code下注册的账号
			if(!empty($codes)){
				$Accountsinfo1 = M('Accountsinfo')->where("yq_code in($codes)")->field("score")->select();
			}
            $zong = 0;
			foreach($Accountsinfo1 as $v){
				$zong += $v['score'];
			}

            if($zong>=500){
				$ling = 18;
			}
			if($zong>=5000){
				$ling = 58;
			}

			//推广好礼 end

			$this->assign("etimes111",$etimes111);
			$this->assign("stimes111",$stimes111);
			$this->assign("etime111",$etime111);
			$this->assign("stime111",$stime111);
			$this->assign("timess",$timess);//下半场时间判断
			$this->assign("etimes13",$etimes13);//下半场时间判断
			$this->assign("stimes13",$stimes13);//下半场时间判断
			$this->assign("etimes12",$etimes12);//上半场时间判断
			$this->assign("stimes12",$stimes12);//上半场时间判断
			$this->assign("count2",$count2);//下半场数量判断
			$this->assign("count",$count);   //上半场数量判断
			$hid = I("hid");
			$this->assign("hid",$hid);
			$this->assign("hongbao",$hongbao);
			$this->assign("birth",$birth);
			$this->assign("jiang_jins",$jiang_jins);
			$this->assign("Accountsinfo",$Accountsinfo);
			$this->assign("jiajiang",$jiajiang);
			$this->assign("bili",$bili);
			$this->assign("touzhu",$touzhu);
			$this->assign("touzhu1",$touzhu1);
			$this->assign("arr",$up_level);
			$this->assign("arr1",$up_level1);
			$this->assign("arr2",$up_level2);
			$this->assign("arr4",$up_level4);
			$this->assign("chongzhi",$chongzhi);
			$this->assign("shou_money",$shou_money);
			$this->assign("huizeng",$huizeng);
			$this->assign("ling",$ling);
			$this->assign("tuiguang",$tuiguang);
			$this->assign("id",$id);
			$this->display();
		}
    }
	public function mobile(){
		$hid = I("hid");
		$this->assign("hid",$hid);
        $this->display();
    }
	public function helpCenter(){
		$hid = I("hid");
		$this->assign("hid",$hid);
		$this->display();
	}
	public function register(){
		$code = I("id");
		$this->assign("code",$code);
		$this->display();
	}
	public function login(){
		$this->display();
	}
	public function dologin(){
		$where['Accounts'] = I("username");
		$pa = I("pwd");
		$data = M('Accountsinfo')
        ->where($where)
        ->find();

		if($data){
			if(trim($data['logonpass'])==$pa){
                if($data['frozen']=='1'){
                    echo 4;die;
                }else{
                    session("user_id",$data['userid']);
                    session("user_name",$data['nickname']);
                    session("login_name",$data['accounts']);
                    session("last_time",$data['lasttime']);
                    $t = date("Y-m-d H:i:s");
					$lastIP = get_real_ip();
                    M('Accountsinfo')->where("userid = '{$data['userid']}'")->save(array("lasttime"=>$t,"LastLogonIP"=>$lastIP));
                    echo 3;
                }
			}else{
				echo 2;
			}
		}else{
			echo 1;
		}
	}
	public function logout(){
		session(null);
		$this->display("login");
	}
	public function ResetPwd(){
		$this->display();
	}
	//忘记密码  找回
	public function resetWay(){
		$user = I("user");
		$date = M('Accountsinfo')->where("accounts = '{$user}'")->find();
		$dat = M("answer")->where("uid=".$date['userid'])->select();
		$this->assign("dat",$dat);
		$this->assign("date",$date);
		$this->display();
	}
	//修改安全密码 确认原安全密码
	function verifySafePwd(){
		if(IS_POST){
			$id = I("id");
			$pass = I("pass");
			$data= M('Accountsinfo')->where("userid='{$id}'")->field("insurepass")->find();
			if($pass == trim($data["insurepass"])){
				echo 0;
			}else{
				echo 1;
			}
		}else{
			$id = I("id");
			$this->assign("id",$id);
			$this->display();
		}
	}
//修改密码
	function verifyPwd2(){
		if(IS_POST){
			$id = I("id");
			$data["LogonPass"] = I("pass");
			M('Accountsinfo')->where("userid='{$id}'")->save($data);
			echo 1;
		}else{
			$id = I("id");
			$this->assign("id",$id);
			$this->display();
		}
	}
	//修改密码
	function verifyPwd3(){
		if(IS_POST){
			$id = I("id");
			$data["LogonPass"] = I("pass");
			M('Accountsinfo')->where("userid='{$id}'")->save($data);
			echo 1;
		}else{
			$id = I("id");
			$this->assign("id",$id);
			$this->display();
		}
	}
	//修改密码
	function verifyPwd4(){
		if(IS_POST){
			$id = I("id");
			$data["LogonPass"] = I("pass");
			M('Accountsinfo')->where("userid='{$id}'")->save($data);
			echo 1;
		}else{
			$id = I("id");
			$this->assign("id",$id);
			$this->display();
		}
	}
	//修改密码
	function verifyPwd5(){
		if(IS_POST){
			$id = I("id");
			$data["LogonPass"] = I("pass");
			M('Accountsinfo')->where("userid='{$id}'")->save($data);
			echo 1;
		}else{
			$id = I("id");
			$this->assign("id",$id);
			$this->display();
		}
	}
	//验证密保问题
	function setQuestion_upd(){
		if(IS_POST){
			$id = I("id");
			$data1 = I("data1");
			$data2 = I("data2");
			$data3 = I("data3");
			$us1 = M("answer")->where(" uid={$id} and qid = {$data1['question1']} and answer = {$data1['answer1']}")->field("qid,answer")->find();
			if($us1){
				echo 1;
			}else{
				echo 2;
			}
			$us2 = M("answer")->where(" uid={$id} and qid = {$data2['question2']} and answer = {$data2['answer2']}")->field("qid,answer")->find();
			if($us2){
				echo 1;
			}else{
				echo 2;
			}
			$us3 = M("answer")->where(" uid={$id} and qid = {$data3['question3']} and answer = {$data3['answer3']}")->field("qid,answer")->find();
			if($us3){
				echo 1;
			}else{
				echo 2;
			}
		}else{
			$id = I("id");
			$date =  M("answer")->where("uid = {$id}")->select();
			foreach($date as $v){
				$qid[] = $v["qid"];
			}
			$qids = implode(",",$qid);
			if($qids){
				$quest = M("question")->where("id in($qids)")->select();
			}

			$this->assign("date",$date);
			$this->assign("arr",$quest);
			$this->assign("id",$id);
			$this->display();
		}
	}

   //手机号找密码
	function setMobile(){
		if(IS_POST){
			$id = I("id");
			$yzm = I("yzm");
			$shouji = I("mobile");
			$yanzheng = M("code")->where("mobile='{$shouji}' and code='{$yzm}'")->find();
			if($yanzheng){
				$data["mobile"] = $shouji;
				M('Accountsinfo')->where("userid='{$id}'")->save($data);
				echo 1;
			}else{
				echo 2;
			}
		}else{
			$id = I("id");
			$this->assign("id",$id);
			$this->display();
		}
	}
	//绑定手机号 发送验证码
	function examine_message(){
		$id = I("id");
		$mobile = I("mobile");
		$shouji2 = M('Accountsinfo')->where("userid='{$id}'")->field("mobile")->find();

		if(trim($mobile) != trim($shouji2['mobile'])){
			echo 3;die;
		}
		$code = yz(6);
		$date = array();
		$date['mobile'] = $mobile;
		$date['code'] = $code;
		$date['ctime'] = time();
		M("code")->add($date);


		//调用类
		include ('./public/duanxin/smsapi.class.php');
		//接口账号
		$uid = 'shifencai';
		//登录密码
		$pwd = 'www123';

		/**
		 * 实例化接口
		 *
		 * @param string $uid 接口账号
		 * @param string $pwd 接口密码
		 */
		$api = new \SmsApi($uid,$pwd);

		//短信内容
		$content = '您的验证码是：'.$code.'，有效期为5分钟！【十分彩网】';
		//发送全文模板短信
		$result = $api->sendAll($mobile,$content);

		if($result['stat']=='100')
		{
			echo 1;
		}else{
			echo 2;
		}
	}
	//邮箱找密码
	function setMail(){
		if(IS_POST){
			$id = I("id");
			$yzm = I("yzm");
			$email= I("email");
			$yanzheng = M("code")->where("email='{$email}' and code='{$yzm}'")->find();
			if($yanzheng){
				$data["email"] = $email;
				M('Accountsinfo')->where("userid='{$id}'")->save($data);
				echo 1;
			}else{
				echo 2;
			}
		}else{
			$id = I("id");
			$this->assign("id",$id);
			$this->display();
		}
	}
	//邮箱找密码 发送验证码
	function examine_message2(){
		$id = I("id");
		$email = I("email");
		$youxiang = M('Accountsinfo')->where("userid='{$id}'")->field("email")->find();

		if(trim($email) != trim($youxiang['email'])){
			echo 2;die;
		}
		$code = yz(6);
		$date = array();
		$date['email'] = $email;
		$date['code'] = $code;
		$date['ctime'] = time();
		M("code")->add($date);
		$title = "邮箱发送验证码";
		$content = '您的验证码是：'.$code.'，有效期为5分钟！【十分彩网】';
		sendmail($email,$title,$content);
		echo 1;
	}




	//预期
	public function yuqi(){
		$hid = I("hid");
		$this->assign("hid",$hid);
		$this->display();
	}

	//银行卡汇款
	public function ebankPay(){
		if($_POST){
			$uid = $_SESSION['user_id'];
			$data['uid'] = $uid;
			$data['number'] = "CZ".date("Ymd").time();
			$data['type'] = 1;
			$data['sbank_name'] = trim(I("bank"));
			$data['sbank_account'] = I("acco");
			$data['sbank_card'] = I("card");
			$data['sbank_kh'] = I("kh");
			$data['money'] = I("money");
			$data['ctime'] = time();
			$data['my_name'] = I("my_name");

			M("order")->add($data);
			echo 1;
		}else{
    		$id = $_SESSION['user_id'];
    		$wanjia = M('Accountsinfo')->where("userid = {$id}")->field("utype")->find();
    		$data = M('Accountsinfo')->where("userid='{$id}'")->field('score,vip')->find();
            if(trim($data['vip'])!='0'){
                $date = M("pay_bankcard")->where("dengji= '{$data['vip']}'")->find();
            }else{
                if(0<=$data['score'] && $data['score']<10){
                    $date = M("pay_bankcard")->where("dengji=1")->find();
                }elseif(10<=$data['score'] && $data['score']<200){
                    $date = M("pay_bankcard")->where("dengji=2")->find();
                }elseif(200<=$data['score'] && $data['score']<1000){
                    $date = M("pay_bankcard")->where("dengji=3")->find();
                }elseif(1000<=$data['score'] && $data['score']<10000){
                    $date = M("pay_bankcard")->where("dengji=4")->find();
                }elseif(10000<=$data['score'] && $data['score']<50000){
                    $date = M("pay_bankcard")->where("dengji=5")->find();
                }elseif(50000<=$data['score'] && $data['score']<250000){
                    $date = M("pay_bankcard")->where("dengji=6")->find();
                }elseif(250000<=$data['score'] && $data['score']<1000000){
                    $date = M("pay_bankcard")->where("dengji=7")->find();
                }elseif(1000000<=$data['score'] && $data['score']<5000000){
                    $date = M("pay_bankcard")->where("dengji=8")->find();
                }elseif(5000000<=$data['score']){
                    $date = M("pay_bankcard")->where("dengji=9")->find();
                }
            }
    		$this->assign("arr",$date);
    		$this->assign("wanjia",$wanjia);
    		$this->display();
		}
	}

	//快捷支付
//	public function quickPay(){
//		$this->display();
//	}
	//支付宝支付
	public function alipay(){
		if($_POST){
			$uid = $_SESSION['user_id'];
			$data['uid'] = $uid;
			$data['number'] = "CZ".date("Ymd").time();
			$data['type'] = 2;
			$data['sbank_name'] = trim(I("bank"));
			$data['sbank_account'] = I("acco");
			$data['sbank_card'] = I("card");
			$data['sbank_kh'] = I("kh");
			$data['money'] = I("money");
			$data['ctime'] = time();
			$data['my_name'] = I("my_name");
			M("order")->add($data);
			echo 1;
		}else{
			$id = $_SESSION['user_id'];
			$wanjia = M('Accountsinfo')->where("userid = {$id}")->field("utype")->find();
			$data = M('Accountsinfo')->where("userid='{$id}'")->field('score,vip')->find();
            if(trim($data['vip'])!='0'){
                $date = M("pay_zhifubao")->where("dengji= '{$data['vip']}'")->find();
            }else{
    			if(0<=$data['score'] && $data['score']<10){
    				$date = M("pay_zhifubao")->where("dengji=1")->find();
    			}elseif(10<=$data['score'] && $data['score']<200){
    				$date = M("pay_zhifubao")->where("dengji=2")->find();
    			}elseif(200<=$data['score'] && $data['score']<1000){
    				$date = M("pay_zhifubao")->where("dengji=3")->find();
    			}elseif(1000<=$data['score'] && $data['score']<10000){
    				$date = M("pay_zhifubao")->where("dengji=4")->find();
    			}elseif(10000<=$data['score'] && $data['score']<50000){
    				$date = M("pay_zhifubao")->where("dengji=5")->find();
    			}elseif(50000<=$data['score'] && $data['score']<250000){
    				$date = M("pay_zhifubao")->where("dengji=6")->find();
    			}elseif(250000<=$data['score'] && $data['score']<1000000){
    				$date = M("pay_zhifubao")->where("dengji=7")->find();
    			}elseif(1000000<=$data['score'] && $data['score']<5000000){
    				$date = M("pay_zhifubao")->where("dengji=8")->find();
    			}elseif(5000000<=$data['score']){
    				$date = M("pay_zhifubao")->where("dengji=9")->find();
    			}
            }
			$this->assign("arr",$date);
			$this->assign("wanjia",$wanjia);
			$this->display();
		}
	}
	//微信支付
	public function wechatPay(){
		if($_POST){
			$uid = $_SESSION['user_id'];
			$data['uid'] = $uid;
			$data['number'] = "CZ".date("Ymd").time();
			$data['type'] = 3;
			$data['sbank_name'] = trim(I("bank"));
			$data['sbank_account'] = I("acco");
			$data['sbank_card'] = I("card");
			$data['sbank_kh'] = I("kh");
			$data['money'] = I("money");
			$data['ctime'] = time();
			$data['my_name'] = I("my_name");
			M("order")->add($data);
			echo 1;
		}else{
			$id = $_SESSION['user_id'];
			$wanjia = M('Accountsinfo')->where("userid = {$id}")->field("utype")->find();
			$data = M('Accountsinfo')->where("userid='{$id}'")->field('score,vip')->find();
            if(trim($data['vip'])!='0'){
                $date = M("pay_weixin")->where("dengji= '{$data['vip']}'")->find();
            }else{
    			if(0<=$data['score'] && $data['score']<10){
    				$date = M("pay_weixin")->where("dengji=1")->find();
    			}elseif(10<=$data['score'] && $data['score']<200){
    				$date = M("pay_weixin")->where("dengji=2")->find();
    			}elseif(200<=$data['score'] && $data['score']<1000){
    				$date = M("pay_weixin")->where("dengji=3")->find();
    			}elseif(1000<=$data['score'] && $data['score']<10000){
    				$date = M("pay_weixin")->where("dengji=4")->find();
    			}elseif(10000<=$data['score'] && $data['score']<50000){
    				$date = M("pay_weixin")->where("dengji=5")->find();
    			}elseif(50000<=$data['score'] && $data['score']<250000){
    				$date = M("pay_weixin")->where("dengji=6")->find();
    			}elseif(250000<=$data['score'] && $data['score']<1000000){
    				$date = M("pay_weixin")->where("dengji=7")->find();
    			}elseif(1000000<=$data['score'] && $data['score']<5000000){
    				$date = M("pay_weixin")->where("dengji=8")->find();
    			}elseif(5000000<=$data['score']){
    				$date = M("pay_weixin")->where("dengji=9")->find();
    			}
            }
			$this->assign("arr",$date);
			$this->assign("wanjia",$wanjia);
			$this->display();
		}
	}


	//提现
	public function withdraw(){
        $uid = $_SESSION['user_id'];
        $res = M('Accountsinfo')->where("userid = '$uid'")->field("money,sheng_money")->find();//余额
        $ban = M("bankcard")->where("uid = '$uid'")->order("id desc")->select(); //账户里添加的银行卡
        $start = strtotime(date("Y-m-d")." 00:00:00");//开始时间
        $end = strtotime(date("Y-m-d")." 23:59:59"); //结束时间
        $co = M("tixian")->where("ctime >= $start and ctime <= $end")->count();//今天提现的次数

        foreach($ban as $ka=>$va){
            $ban[$ka]['card'] = "*******".substr(trim($va['card']),-4);
            $ban[$ka]['uname'] = "**".mb_substr(trim($va['uname']),-2,2,'utf-8');
        }

       //投注的钱数
		$touzhu = M("jiaoyi")->where("uid={$uid} and type=3")->order("id asc")->select();
		$touzhus1 = 0;
		foreach($touzhu as $k2=>$v2){
			$haha[] = $v2['zhi_money'];
			$ctime[] = $v2['ctime'];
		}
		foreach($haha as $v3){
			$touzhus1 += $v3;
		}

		if($touzhus1>=$res['sheng_money'] && $res['sheng_money']=='.0000'){
            $keti = $res['money'];
		}else{
			$keti = 0;
		}

        $this->assign("cc",$keti);
        $this->assign("res",$res);
        $this->assign("ban",$ban);
        $this->assign("co",$co);
		$this->display();
	}
    //添加 提现
    public function tx_do(){
        $data = array(
            'numbers' => 'TX'.date(md).time(),
            'uid' => $_SESSION['user_id'],
            'money' => $_POST['ti_money'],
            'bank_id' => $_POST['aid'],
            'ctime' => time()
        );
        $safep = I("safep");
        $res = M("accountsinfo")->where("userid = '{$data['uid']}' and insurepass = '$safep'")->find();
        if(empty($res)){
            echo 2;die;
        }
        M("tixian")->add($data);
        $mm = M('Accountsinfo')->where("userid = '{$data['uid']}'")->field("money")->find();
        $cp['number'] = "TX".date(md).time();
        $cp['type'] = '2';
        $cp['zhi_money'] = $data['money'];
        $cp['ky_money'] = $mm['money'] - $data['money'];
        $cp['ctime'] = time();
        $cp['uid'] = $data['uid'];
        $cp['remark'] = '提现扣款';
        M("jiaoyi")->add($cp);
        M('Accountsinfo')->where("userid = '{$data['uid']}'")->setDec("money",$data['money']);
        echo 1;
    }

	//昨日到账平均时间

	public function pingjun(){

	}

   //第三方 扫码支付
	public function scanPay(){
	    $arr = M("pay_three")->where("status=1")->find();
        if($arr['id']==4){
             $type_array[] = array('key'=>'weixin_scan','val'=>'微信');
             $type_array[] = array('key'=>'alipay_scan','val'=>'支付宝');
             $type_array[] = array('key'=>'tenpay_scan','val'=>'qq钱包');
             $type_array[] = array('key'=>'jdpay_scan','val'=>'京东钱包');
             $type_array[] = array('key'=>'bdpay_scan','val'=>'百度钱包');
        }elseif($arr['id']==2){
            $type_array[] = array('key'=>'weixin_scan','val'=>'微信');
            $type_array[] = array('key'=>'alipay_scan','val'=>'支付宝');
            $type_array[] = array('key'=>'qq_scan','val'=>'QQ扫码');
            $type_array[] = array('key'=>'jdpay_scan','val'=>'京东扫码');
            $type_array[] = array('key'=>'ylpay_scan','val'=>'银联扫码');
        }
        $this->assign("id",$arr['id']);
        $this->assign("type_array",$type_array);
		$this->display();
	}
	/*
	 *   发起支付
	 * */
	function doScanPay()
    {
        $paytype = I("post.paytype");
        $typeid = I("post.typeid");
        $amount = I("post.amount");
        if (empty($paytype) || empty($typeid) || empty($amount)) {
            echo "1";
            die;
        }
        if (!preg_match('/^[0-9]+(.[0-9]{1,2})?$/', $amount)) {
            echo "2";
            die;
        }
        //智通宝
        if ($paytype == 4) {
            $type_array[] = "weixin_scan";
            $type_array[] = "alipay_scan";
            $type_array[] = "tenpay_scan";
            $type_array[] = "jdpay_scan";
            $type_array[] = "bdpay_scan";
            if (!in_array($typeid, $type_array)) {
                echo "3";
                die;
            }
            $uid = $_SESSION['user_id'];
            $data['uid'] = $uid;
            $data['number'] = "CZ" . date("Ymd") . time();
            $data['type'] = 4;
            $data['pay_three_id'] = $paytype;
            $data['paytype'] = $typeid;
            $data['money'] = $amount;
            $data['ctime'] = time();
            $arr = M("order")->add($data);
            if ($arr) {
                //引入支付类
                include('public/payapi/zhitongbao/phpqrcode.php');
                include_once("public/payapi/zhitongbao/merchant.php");
                //接收参数
                $merchant_code = 100100003883;//商户号，123001002003是测试商户号，调试时要更换商家自己的商户号
                $service_type = $typeid;//微信：weixin_scan 支付宝：alipay_scan qq钱包：tenpay_scan
                $notify_url = "http://" . $_SERVER['HTTP_HOST'] . "/Notify/zhitongbao_notify";
                $interface_version = "V3.1";
                $client_ip = $_SERVER["REMOTE_ADDR"];
                $sign_type = "RSA-S";
                $order_no = $data['number'];
                $order_time = date("Y-m-d H:i:s");
                $order_amount = $amount;
                $product_name = "用户充值";
                //组装参数
                $signStr = "";
                $signStr = $signStr . "client_ip=" . $client_ip . "&";
                $signStr = $signStr . "interface_version=" . $interface_version . "&";
                $signStr = $signStr . "merchant_code=" . $merchant_code . "&";
                $signStr = $signStr . "notify_url=" . $notify_url . "&";
                $signStr = $signStr . "order_amount=" . $order_amount . "&";
                $signStr = $signStr . "order_no=" . $order_no . "&";
                $signStr = $signStr . "order_time=" . $order_time . "&";
                $signStr = $signStr . "product_name=" . $product_name . "&";
                $signStr = $signStr . "service_type=" . $service_type;
                /////////////////////////////////初始化商户私钥//////////////////////////////////////
                $merchant_private_key = openssl_get_privatekey($merchant_private_key);
                openssl_sign($signStr, $sign_info, $merchant_private_key, OPENSSL_ALGO_MD5);
                $sign = base64_encode($sign_info);
                $postdata = array('merchant_code' => $merchant_code,
                    'service_type' => $service_type,
                    'notify_url' => $notify_url,
                    'interface_version' => $interface_version,
                    'sign_type' => $sign_type,
                    'order_no' => $order_no,
                    'client_ip' => $client_ip,
                    'sign' => $sign,
                    'order_time' => $order_time,
                    'order_amount' => $order_amount,
                    'product_name' => $product_name);
                $ch = curl_init();
                curl_setopt($ch, CURLOPT_URL, "https://api.ztbaopay.com/gateway/api/scanpay");
                curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
                curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
                curl_setopt($ch, CURLOPT_POST, true);
                curl_setopt($ch, CURLOPT_HEADER, false);
                curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($postdata));
                curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
                $response = curl_exec($ch);
                curl_close($ch);
                $res = simplexml_load_string($response);
                $res = json_encode($res);
                $return = json_decode($res, true);
                if ($return['response']['resp_code'] == "SUCCESS" && $return['response']['result_code'] == 0) {
                    echo $return['response']['qrcode'];
                    die;
                } else {
                    echo "4";
                    die;
                }
            } else {
                echo "4";
                die;
            }
        } elseif ($paytype == 2) {//多得宝
            $type_array[] = "weixin_scan";
            $type_array[] = "alipay_scan";
            $type_array[] = "qq_scan";
            $type_array[] = "jdpay_scan";
            $type_array[] = "ylpay_scan";
            if (!in_array($typeid, $type_array)) {
                echo "3";
                die;
            }
            $uid = $_SESSION['user_id'];
            $data['uid'] = $uid;
            $data['number'] = "CZ" . date("Ymd") . time();
            $data['type'] = 4;
            $data['pay_three_id'] = $paytype;
            $data['paytype'] = $typeid;
            $data['money'] = $amount;
            $data['ctime'] = time();
            $arr = M("order")->add($data);
            if ($arr) {
                //引入支付类
                include('public/payapi/duodebao/phpqrcode.php');
                include_once("public/payapi/duodebao/merchant.php");
                //接收参数
                $merchant_code = 1000790030;//商户号，123001002003是测试商户号，调试时要更换商家自己的商户号
                $service_type = $typeid;//微信：weixin_scan 支付宝：alipay_scan qq钱包：tenpay_scan
                $notify_url = "http://" . $_SERVER['HTTP_HOST'] . "/Notify/duodebao_notify";
                $interface_version = "V3.1";
                $client_ip = $_SERVER["REMOTE_ADDR"];
                $sign_type = "RSA-S";
                $order_no = $data['number'];
                $order_time = date("Y-m-d H:i:s");
                $order_amount = $amount;
                $product_name = "用户充值";
                //组装参数
                $signStr = "";
                $signStr = $signStr . "client_ip=" . $client_ip . "&";
                $signStr = $signStr . "interface_version=" . $interface_version . "&";
                $signStr = $signStr . "merchant_code=" . $merchant_code . "&";
                $signStr = $signStr . "notify_url=" . $notify_url . "&";
                $signStr = $signStr . "order_amount=" . $order_amount . "&";
                $signStr = $signStr . "order_no=" . $order_no . "&";
                $signStr = $signStr . "order_time=" . $order_time . "&";
                $signStr = $signStr . "product_name=" . $product_name . "&";
                $signStr = $signStr . "service_type=" . $service_type;
                /////////////////////////////////初始化商户私钥//////////////////////////////////////
                $merchant_private_key = openssl_get_privatekey($merchant_private_key);
                openssl_sign($signStr, $sign_info, $merchant_private_key, OPENSSL_ALGO_MD5);
                $sign = base64_encode($sign_info);
                $postdata = array('merchant_code' => $merchant_code,
                    'service_type' => $service_type,
                    'notify_url' => $notify_url,
                    'interface_version' => $interface_version,
                    'sign_type' => $sign_type,
                    'order_no' => $order_no,
                    'client_ip' => $client_ip,
                    'sign' => $sign,
                    'order_time' => $order_time,
                    'order_amount' => $order_amount,
                    'product_name' => $product_name);
                $ch = curl_init();
                curl_setopt($ch, CURLOPT_URL, "https://api.ddbill.com/gateway/api/scanpay");
                curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
                curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
                curl_setopt($ch, CURLOPT_POST, true);
                curl_setopt($ch, CURLOPT_HEADER, false);
                curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($postdata));
                curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
                $response = curl_exec($ch);
                curl_close($ch);
                $res = simplexml_load_string($response);
                $res = json_encode($res);
                $return = json_decode($res, true);
                if ($return['response']['resp_code'] == "SUCCESS" && $return['response']['result_code'] == 0) {
                    echo $return['response']['qrcode'];
                    die;
                } else {
                    echo "4";
                    die;
                }
            } else {
                echo "4";
                die;
            }

        }
    }

























}